<?php

use yii\helpers\Html;
use yii\grid\GridView;
use common\models\Product;
use common\models\Company;

/* @var $this yii\web\View */
/* @var $searchModel common\models\ProductSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */

$this->title = '商品';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="product-index" style="overflow:auto;">

<!--     <h1><?= Html::encode($this->title) ?></h1> -->
    <?php // echo $this->render('_search', ['model' => $searchModel]); ?>

    <p>
        <?= Html::a('添加商品', ['create'], ['class' => 'btn btn-success']) ?>
    </p>
    <?= GridView::widget([
        'dataProvider' => $dataProvider,
        'filterModel' => $searchModel,
        'tableOptions' => ['class' => 'table table-striped table-bordered','style'=>'width:auto;max-width:none;'],
        'options' => ['class' => 'grid-view','style'=>'overflow:auto'],
        'columns' => [
            //['class' => 'yii\grid\SerialColumn'],

            'id',
            'name',
            'title',
            'keywords',
            [
                'attribute' => 'img_url',
                'format' => 'image',
                'value'=>function($model) { return $model->img_url.'!s100'; },
            ],
            //'des:ntext',
            //'market_price',
             'product_price',
            // 'promotion_price',
             'price_unit',
            /*[
                'attribute' => 'price_unit',
                'value' => function ($model, $key, $index, $column) {
                    return Product::itemAlias("price_unit", $model->price_unit);
                },
                'filter'=>Product::itemAlias("price_unit"),
            ],*/
            /* 'weight',
             [
                'attribute' => 'weight_unit',
                'value' => function ($model, $key, $index, $column) {
                    return Product::itemAlias("weight_unit", $model->weight_unit);
                },
                'filter'=>Product::itemAlias("weight_unit"),
            ],*/
            [
                'attribute' => 'company_id',
                'value' => 'company.company_name',
                'filter'=>Product::listCompany(),
            ],
            [
                'attribute' => 'brand_name',
                'value' => 'brand.name',
                'filter'=>Product::listBrand(),
            ],

            [
                'attribute' => 'category_name',
                //'value' => 'category.name',
                'value' => function ($model, $key, $index, $column) {
                    $cate = Product::ProductCategoryname($model->id);
                    return implode($cate, ',');
                },
                'filter'=>Product::listCate(),
            ],
            // 'send_sample',
            // 'sort_numer',
            // 'hot_sort',
             'stock',
            // 'serial_number',
            // 'full_cut_shipping_free',
            // 'supply',
            [
                'attribute' => 'is_show',
                'value' => function ($model, $key, $index, $column) {
                    return Product::itemAlias("is_show", $model->is_show);
                },
                'filter'=>Product::itemAlias("is_show"),
            ],
             'create_time',

            ['class' => 'yii\grid\ActionColumn'],
        ],
    ]); ?>
</div>
